.TH std::negation 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::negation \- std::negation

.SH Synopsis
   Defined in header <type_traits>
   template< class B >              \fI(since C++17)\fP
   struct negation;

   Forms the logical negation of the type trait B.

   The type std::negation<B> is a UnaryTypeTrait with a base characteristic of
   std::bool_constant<!bool(B::value)>.

   If the program adds specializations for std::negation or std::negation_v, the
   behavior is undefined.

.SH Template parameters

   B - any type such that the expression bool(B::value) is a valid constant expression

   Helper variable template

   template< class B >                                     \fI(since C++17)\fP
   inline constexpr bool negation_v = negation<B>::value;



Inherited from std::integral_constant

.SH Member constants

   value    true if B has a member ::value that is false when explicitly converted to
   \fB[static]\fP bool, false otherwise
            \fI(public static member constant)\fP

.SH Member functions

   operator bool converts the object to bool, returns value
                 \fI(public member function)\fP
   operator()    returns value
   \fI(C++14)\fP       \fI(public member function)\fP

.SH Member types

   Type       Definition
   value_type bool
   type       std::integral_constant<bool, value>

.SH Possible implementation

   template<class B>
   struct negation : std::bool_constant<!bool(B::value)> { };

.SH Notes

      Feature-test macro     Value    Std             Feature
   __cpp_lib_logical_traits 201510L \fI(C++17)\fP Logical operator type traits

.SH Example


// Run this code

 #include <iostream>
 #include <type_traits>

 static_assert(
     std::is_same<
         std::bool_constant<false>,
         typename std::negation<std::bool_constant<true>>::type>::value,
     "");
 static_assert(
     std::is_same<
         std::bool_constant<true>,
         typename std::negation<std::bool_constant<false>>::type>::value,
     "");

 int main()
 {
     std::cout << std::boolalpha;
     std::cout << std::negation<std::bool_constant<true>>::value << '\\n';
     std::cout << std::negation<std::bool_constant<false>>::value << '\\n';
 }

.SH Output:

 false
 true

.SH See also

   conjunction       variadic logical AND metafunction
   \fI(C++17)\fP           \fI(class template)\fP
   disjunction       variadic logical OR metafunction
   \fI(C++17)\fP           \fI(class template)\fP
   integral_constant
   bool_constant     compile-time constant of specified type with specified value
   \fI(C++11)\fP           \fI(class template)\fP
   \fI(C++17)\fP
